package com.ljx.autoConfig;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2022/11/17 15:04
 * @Version 1.0
 * 定义一个自动装配类
 * 用来完成Bean的创建工作
 */
@Configuration // 标记该类为配置类
@EnableConfigurationProperties(LjxProperties.class) // 开启属性配置
@ConditionalOnClass(LjxService.class) //只要LjxService被引入后该类才会被创建
@ConditionalOnProperty(prefix = "ljx",value = "enable",matchIfMissing = true) //如果引用这没有给定相关属性值则采用默认值
public class LjxAutoConfigration {
	@Autowired
	private LjxProperties ljxProperties;
	@Bean
	@ConditionalOnMissingBean // 当IOC容器不存在该bean对象时，才会创建
	public LjxService ljxService(){
		return new LjxService(ljxProperties);
	}
}
